package com.example.awa;

    // 鸭子抽象类
    abstract class Duck {
        protected FlyBehavior flyBehavior;
        protected QuackBehavior quackBehavior;

        public Duck() {}

        // 执行飞行行为
        public void performFly() {
            flyBehavior.fly();
        }

        // 执行呱呱叫行为
        public void performQuack() {
            quackBehavior.quack();
        }

        // 设置飞行行为
        public void setFlyBehavior(FlyBehavior flyBehavior) {
            this.flyBehavior = flyBehavior;
        }

        // 设置呱呱叫行为
        public void setQuackBehavior(QuackBehavior quackBehavior) {
            this.quackBehavior = quackBehavior;
        }

        // 游泳方法，所有鸭子都会游泳
        public void swim() {
            System.out.println("鸭子游泳");
        }

        // 展示鸭子外观，由具体鸭子类实现
        public abstract void display();
    }

    // 绿头鸭类
    class MallardDuck extends Duck {
        public MallardDuck() {
            flyBehavior = new FlyWithWings();
            quackBehavior = new Quack();
        }

        @Override
        public void display() {
            System.out.println("绿头鸭");
        }
    }

    // 红头鸭类
    class RedheadDuck extends Duck {
        public RedheadDuck() {
            flyBehavior = new FlyWithWings();
            quackBehavior = new Quack();
        }

        @Override
        public void display() {
            System.out.println("红头鸭");
        }
    }

    // 橡皮鸭类
    class RubberDuck extends Duck {
        public RubberDuck() {
            flyBehavior = new FlyNoWay();
            quackBehavior = new Squeak();
        }

        @Override
        public void display() {
            System.out.println("橡皮鸭");
        }
    }

    // 诱饵鸭类
    class DecoyDuck extends Duck {
        public DecoyDuck() {
            flyBehavior = new FlyNoWay();
            quackBehavior = new MuteQuack();
        }

        @Override
        public void display() {
            System.out.println("诱饵鸭");
        }
    }



